define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/shorder/index' + location.search,
                    add_url: 'order/shorder/add',
                    // edit_url: 'order/reorder/edit',
                    //del_url: 'order/reorder/del',
                    multi_url: 'order/shorder/multi',
                    import_url: 'order/shorder/import',
                    table: 'shorder',
                }
            });

            var table = $("#table");
            Fast.config.openArea = ['70%','70%'];
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'order_user', title: __('商城类型'),searchList: {"1":"VIP商城","2":"收货商城"}, formatter: Table.api.formatter.flag},
                        {field: 'account', title: __('买家账号'), operate: 'LIKE'},
                        {field: 'order_sn', title: __('订单'), operate: 'LIKE'},
                        // {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'game', title: __('游戏'), operate: 'LIKE'},
                        {field: 'area', title: __('游戏区'), operate: 'LIKE'},
                        {field: 'server', title: __('游戏服'), operate: 'LIKE'},
                        {field: 'cross', title: __('跨区'), operate: 'LIKE'},
                        {field: 'invite', title: __('推广码'), operate: 'LIKE'},
                        {field: 'num', title: __('出货数量')},
                        {field: 'price', title: __('收货单价')},
                        {field: 'priceAll', title: __('总金额')},
                        {field: 'status', title: __('状态'),searchList: {"1":"待支付","2":"待发货","3":"已发货","4":"已取消","5":"已完成"}, formatter: Table.api.formatter.flag},
                        {field: 'ontime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'receiving.role_account', title: __('角色名称')},
                        {field: 'receiving.role_level', title: __('角色等级')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
//                                 {
//                                     name: 'detail',
//                                     text: __(''),
//                                     title: __('商品详情'),
//                                     classname: 'btn btn-xs btn-primary btn-dialog',
//                                     icon: 'fa fa-list',
//                                     url: 'goods/goods/edit?order_id={id}',

//                                 },
                                {
                                    name: 'manage',
                                    text: __(''),
                                    title: __('管控订单'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-retweet',
                                    url: 'order/shorder/manage',

                                },
                                {
                                    name: 'chat',
                                    text: __(''),
                                    title: __('查看卖家聊天记录'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-bell-o',
                                    url: 'order/shorder/chat',

                                },
                                {
                                    name: 'online',
                                    text: __(''),
                                    title: __('联系买/卖家'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-handshake-o',
                                    url: 'order/shorder/online',

                                },

                                {
                                    name: 'info',
                                    text: __(''),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'order/shorder/info',

                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});